<?php

namespace app\api\controller;

use think\Request;
use app\api\model\ProjectTasks;
class Task extends Controller
{
    public $model;
    public $user;

    /**
     * 构造函数
     * @param Request|null $request
     * @throws \app\common\exception\BaseException
     * @throws \think\exception\DbException
     */
    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        $this->model = new ProjectTasks();
        $this->user = $this->getUserInfo();
    }

    /**
     * 列表
     * @throws \think\exception\DbException
     */
    public function list(){
        $datatype = $this->request->param('datatype');
        $list = $this->model->list($datatype,$this->user['id']);
        return $this->renderSuccess(compact('list'));
    }
    //详情
    public function detail($id){
        $detail = $this->model->detail($id);
        return $this->renderSuccess(compact('detail'));
    }
    //编辑
    public function edit($id){
        $detail = $this->model->detail($id);
        $param = $this->request->param();
        if(!empty($param['token'])){
            unset($param['token']);
        }
        $result = $detail->editInfo($param);
        if($result){
            return $this->renderSuccess([],'操作成功');
        }
        return $this->renderError('操作失败');
    }

    /**
     * 查询日、月列表
     * @return array
     * @throws \think\exception\DbException
     */
    public function searchList(){
        $searchType = $this->request->param('searchType');
        $list = $this->model->search($searchType,$this->user['id']);
        return $this->renderSuccess(compact('list'));
    }

    /**
     * 订单总量
     * @return array
     */
    public function total(){
        $total = $this->model->orderTotal($this->user['id']);
        return $this->renderSuccess(compact('total'));
    }

}